package svnProjectGroupB;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class Email {
	public static void sendFile(String to, String fileName) throws MessagingException {
		// http://www.tutorialspoint.com/java/java_sending_email.htm
		// Couldn't do it without password, so mad a new gmail account
		String from = "ivanraychevtest@gmail.com";
		String password = "fuckingpassword";
		Properties props = System.getProperties();
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.auth", "true");
		props.put("mail.debug", "false");
		props.put("mail.smtp.ssl.enable", "true");
		Session session = Session.getInstance(props,
				(Authenticator) new GMailAuthenticator(from, password));

		try {
			MimeMessage message = new MimeMessage(session);			
			message.setFrom(new InternetAddress(from));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(
					to));
			message.setSubject("SVN group project file.");
			BodyPart messageBodyPart = new MimeBodyPart();
			messageBodyPart.setText("SVN group project email, file attatched");
			Multipart multipart = new MimeMultipart();
			multipart.addBodyPart(messageBodyPart);
		    messageBodyPart = new MimeBodyPart();
		    DataSource source = new FileDataSource(fileName);
		    messageBodyPart.setDataHandler(new DataHandler(source));
		    messageBodyPart.setFileName(fileName);
		    message.setContent(multipart );
		    multipart.addBodyPart(messageBodyPart);
			Transport.send(message);
		} catch (MessagingException mex) {
			throw new MessagingException("Error sending message", mex);
		}
	}
}

